<?php
$competition = $data['competition'];
//dump($data);
//dump($_ENV);

$now = strtotime(date('y-m-d h:i:s')); // 当前时间
if ($now < strtotime($competition['start_time'])) {
    $state = 0; // 未开始
} else if ($now < strtotime($competition['end_time'])) {
    $state = 1; // 进行中
} else {
    $state = 2; // 已结束
}

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <include file="Common/meta"/>
    <title>竞赛详情 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link"/>
</head>
<body>
<header class="layout-header">
    <div class="container">
        <h1 class="title">{$competition['title']}</h1>
        <a class="header-back" href="/competition/listPage"><i class="icon icon-left"></i></a>
    </div>
</header>
<div class="layout-body">
    <div class="container">
        <section class="article-box box-cpt">
            <h1 class="article-title">{$competition['title']} </h1>
            <div class="article-info">
                <div class="owner">
                    <if condition="$competition['type'] eq 0">
                        <div>主办方： 平台</div>
                        <else/>
                        <div>主办方： {$competition['school']}</div>
                    </if>
                    <div>
                        比赛时间：{$competition['start_time']|strtotime|date="Y.m.d",###} -
                        {$competition['end_time']|strtotime|date="Y.m.d",###}
                    </div>
                </div>
                <div class="article-time">
                    发布时间:{$competition['create_time']|strtotime|date="Y-m-d H:i",###}
                </div>
                <div>
                    地址：{$competition['local']}
                </div>
            </div>

            <article>
                {$competition['contain']}
            </article>
            <div>
                <if condition="$state neq 2">
                    <button id="signup" class='btn btn-primary cpt-join-btn'>报名参赛</button>
                    <elseif condition="$state eq 2"/>
                    <a id="signup" class="signin disabled" href="#">报名已经结束</a>
                    <else/>
                </if>
                <!-- <div>
                    <if condition="$state neq 2">
                        <a class="download-table" href="{$competition['file']}" target="_blank"><i class="icon icon-download"></i> 下载报名表</a>

                    </if>
                    <if condition="$data['is_join']">
                        <a id="signup" class="signin disabled" href="#">已报名</a>
                    <elseif condition="$state eq 2" />
                        <a id="signup" class="signin disabled" href="#">报名已经结束</a>
                    <else />
                        <input id="upload-file" class="hide" type="file" value="选择报名表">
                        <a id="signup" class="signin" href="#"><i class="icon icon-signin"></i> 报名（请先下载报名表并填写相关信息）</a>
                    </if>
                </div> -->
            </div>
        </section>
    </div>
</div>
<!-- 报名弹出框 -->
<div id="like-wrap" class="like-wrap">
    <section class="box box-like">
        <div class="box-body">
            <div class="tc-logo-box">
                <img class="logo" src="/public/asset/img/logo_blue.png">
                <div class="text">竞赛报名</div>
            </div>
            <!--<div class="form-group">
                <label class="control-label">姓名：</label>
                <div class="form-control-static">{$_ENV['user']['name']}</div>
            </div>-->
            <a id="select-file" class="btn btn-primary" href="#">点击上传报名表</a><span id="file-name" class="file-name">未选择报名表</span>
            <!--<input class="input-file" type="file">-->
            <input id="start-signin" class="login-btn" type="button" value="确认报名">
        </div><!-- ./box-body -->
    </section>
</div><!-- ./like-wrap -->
<script>
    var page = {
        userType: '{$_ENV['user']['type']}',
        competitionId: '{$competition['cpt_id']}'
    };
</script>
<include file="Common/script"/>
<script>
        // 竞赛报名
        $('#signup').on('click', function () {
            eui.alert('请用电脑访问 tswcapp.com 进行报名');
        });
        // if (page.userType !== '' && page.userType !== '1') {
        //     eui.msg('只有学生才可以报名');
        //     return;
        // }

        // if (page.userType !== '1') {
        //     $('#login-wrap').dialog();
        //     return;
        // }

        // console.log('显示');
        // $('#like-wrap').dialog();
        // /*// 如果未登录，跳转到登陆界面

        //  $('#upload-file').trigger('click');*/


    //});
    // $('#select-file').on('click', function () {
    //     $('#upload-file').trigger('click');
    // });

    // var hasSelect = false;
    // var files;
    // $('#start-signin').on('click', function () {
    //     if (!hasSelect) {
    //         eui.msg('请上传报名表');
    //         return;
    //     }
    //     var formData = new FormData();
    //     formData.append('cpt_id', page.competitionId);
    //     formData.append('file', files[0]);

    //     $.ajax({
    //         url: '/competition/join',
    //         data: formData,
    //         type: 'POST',
    //         dataType: 'json',
    //         processData: false,
    //         contentType: false,
    //         success: function (obj) {
    //             if (obj.code === 0) {
    //                 eui.msg('报名成功');
    //                 setTimeout(function () {
    //                     location.reload(true);
    //                 }, 800);
    //             } else {
    //                 eui.alert('报名失败，' + obj.msg);
    //             }
    //         },
    //         error: function () {
    //             eui.alert('系统出错');
    //         }
    //     })
    // });

    // $('#upload-file').on('change', function () {

    //     if (!$(this).val()) {
    //         return;
    //     }

    //     files = $('#upload-file')[0].files;
    //     /*
    //      if (!files.length) {
    //      eui.msg('请选择报名表');
    //      return;
    //      }*/
    //     if (files.length) {
    //         hasSelect = true;
    //         $('#file-name').text('已选择文件');
    //     }
    // });
</script>
</body>
</html>

